﻿using Chimp.Core.Physics;
using OpenTK;

namespace Chimp.Core
{
    public class ChimpSprite : ChimpBase
    {
        public ChimpSprite()
        {
        }

        public ChimpSprite(string name, string ext, Vector2 size, float mass, float density)
        {
            Visual = new ChimpTexture2D(name + "." + ext);

            Normal = new ChimpTexture2D(name + "_NORM." + ext);

            Specular = new ChimpTexture2D(name + "_SPEC." + ext);
            Size = size;
            Color = new Vector4(1, 1, 1, 1);
            Body = new ChimpRBody(mass);
            Shape = ChimpRShape.CreateBox(0, 0, size.X, size.Y, Body, density);
        }

        public ChimpRBody Body { get; set; }
        public ChimpRShape Shape { get; set; }
        public ChimpTexture2D Visual { get; set; }
        public ChimpTexture2D Normal { get; set; }
        public ChimpTexture2D Specular { get; set; }

        public Vector4 Color { get; set; }

        public override void SetPos(Vector2 pos)
        {
            base.SetPos(pos);
            Pos = pos;
            //   Body.B.Position = new Microsoft.Xna.Framework.Vector2(pos.X, pos.Y);
        }

        public override bool OnUpdate(Vector2 pos)
        {
            base.OnUpdate(pos);
            return false;
            //Pos = new Vector2(Body.B.Position.X, Body.B.Position.Y);
            //Rotation = MathHelper.RadiansToDegrees(Body.B.Rotation);
        }

        public override void OnDraw(Vector2 pos)
        {
            //       pos += DrawPos;
            pos = DrawPos;
            float a = DrawRotation;
            float s = DrawScale;
            ChimpDraw.BlendMode = ChimpBlend.Alpha;
            foreach (ChimpLight l in Scene.LightList)
            {
                ChimpDraw.Image(new Vector4(pos.X - Size.X/2.0f, pos.Y - Size.Y/2.0f, Size.X, Size.Y), a, s, Color,
                                Visual, Normal, Specular, l);
                ChimpDraw.BlendMode = ChimpBlend.Lighten;
            }
        }
    }
}